// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TUCoreTypes.h"
#include "TUBaseWeapon.generated.h"

class USkeletalMeshComponent;
class UNiagaraSystem;
class UNiagaraComponent;

UCLASS()
class THEMUP_API ATUBaseWeapon : public AActor
{
	GENERATED_BODY()
	
public:	
	ATUBaseWeapon();
	FOnClipEmptySignature OnClipEmpty;
	virtual void StartFire();
	virtual void StopFire();
	bool IsFiring() const;
	FAmmoData GetAmmoData() const { return CurrentAmmo; }
	void LogAmmo();
	bool IsClipEmpty() const;
	void ChangeClip();
	bool CanReload() const;
	FWeaponUIData GetUIData() const { return UIData; }
	bool TryToAddAmmo(int32 ClipsAmount);
	bool IsAmmoFull() const;
	bool IsAmmoEmpty() const;

protected:
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
	USkeletalMeshComponent* WeaponMesh;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	FName MuzzleSocketName = "MuzzleSocket";
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	float TraceMaxDistance = 10000.0;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	FAmmoData DefaultAmmo {
	15, 10, false
	};
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UI")
	FWeaponUIData UIData;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "VFX")
	UNiagaraSystem* MuzzleFX;
	
	
	virtual void BeginPlay() override;
	bool GetPlayerViewPoint(FVector& ViewLocation, FRotator& ViewRotation) const;
	FVector GetMuzzleWorldLocation() const;
	void MakeHit(FHitResult& HitResult, const FVector& TraceStart, const FVector& TraceEnd);
	virtual void MakeShot();
	virtual bool GetTraceData(FVector& TraceStart, FVector& TraceEnd) const;
	void DecreaseAmmo();
	UNiagaraComponent* SpawnMuzzleFX();

	bool FireInProgress = false;


private:
	FAmmoData CurrentAmmo;

};
